// pages/yoshop/article/all.js
let _this;
let common = require('../../utils/common.js');
let Bmob = require('../../utils/bmob.js');
let App = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    channels: [],
    courses: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    _this = this;
    Bmob.initialize("8bbd2fa87eece23337234b59c300fb2e", "0422786c4a1502011b37da0d9f437770")

    wx.setNavigationBarTitle({
      title: '全部课程',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    _this.getAllChannels()
    _this.getAllCourses()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 获取全部课程
   */
  getAllCourses: function() {
    let _url = 'classes/Article'

    App._get(_url, {}, function(res) {
      _this.setData({
        courses: res.results
      })
    })
  },

  /**
   * 获取全部分类
   */
  getAllChannels: function() {
    let _url = "classes/Channel?order=cIndex"

    App._get(_url, {}, function(res){
      console.log(res.results)
      _this.setData({
        channels: res.results
      })
    })
  }

})